package com.itbour.service.tg.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.itbour.com.page.JspPage;
import com.itbour.com.page.Page;
import com.itbour.common.util.StringUtils;
import com.itbour.dao.tg.SearchTagInfoDao;
import com.itbour.dto.tg.SearchTagInfoDto;
import com.itbour.service.tg.SearchTagInfoService;

public class SearchTagInfoServiceImpl implements SearchTagInfoService{

	private SearchTagInfoDao searchTagInfoDao;
	@Override
	public Page pageTagInfoPg(Map<String, Object> param, Integer pageNo,
			Integer pageSize) {
		Page result = null;
		
		// 实际起始位置
		int skipResults = JspPage.getStartOfPage(pageNo, pageSize);
		int totalSize = searchTagInfoDao.searchTagInfoCnt(param);
		
		while(totalSize >0 && totalSize <= skipResults){
			skipResults= skipResults - pageSize;
			pageNo = pageNo -1;
		}
		
		// 分页检索
		param.put("pageSize", pageSize);
		param.put("skipResults", skipResults);
		List<SearchTagInfoDto> data = searchTagInfoDao.searchTagInfo(param);

		result = new JspPage(skipResults, totalSize, pageSize, data);
		return result;
	}
	public SearchTagInfoDao getSearchTagInfoDao() {
		return searchTagInfoDao;
	}
	public void setSearchTagInfoDao(SearchTagInfoDao searchTagInfoDao) {
		this.searchTagInfoDao = searchTagInfoDao;
	}
	@Override
	public void updSearch(Map<String, Object> param) {
		searchTagInfoDao.updateSearchInfoById(param);
		
	}
	@Override
	public void delSearch(String ids) {
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("ids", StringUtils.listToString2(StringUtils.stringToList2(ids)));
		searchTagInfoDao.deleteSearchInfoLogic(param);
		
	
		
	}
	@Override
	public void addSearch(SearchTagInfoDto searchInfo) {
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("name", searchInfo.getName());
		param.put("type", searchInfo.getType());
		param.put("create_time", searchInfo.getCreate_time());
		param.put("update_by", searchInfo.getUpdate_by());
		searchTagInfoDao.insertSearchInfo(param);
	}
	@Override
	public List<SearchTagInfoDto> selectSearchInfo(Map<String, Object> param) {

		return searchTagInfoDao.selectSearchInfo(param);
	}

}
